package com.example.casper.jnuexperiment2025;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

public class ImageViewActivity extends AppCompatActivity {
    private Button buttonPrevious,buttonNext;
    private ImageView imageViewFunny;
    private int[] imageIDArray = {R.drawable.funny_1, R.drawable.funny_2
            , R.drawable.funny_3, R.drawable.funny_4, R.drawable.funny_5
            , R.drawable.funny_6
    };
    private int imageIDArrayCurrentIndex;
    public ImageViewActivity() {
        imageIDArrayCurrentIndex = 0;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_image_view);
        buttonPrevious = findViewById(R.id.button_previous);
        buttonNext =findViewById(R.id.button_next);
        imageViewFunny = findViewById(R.id.image_view_funny);
        buttonPrevious.setOnClickListener(new MyButtonClickListener());
        buttonNext.setOnClickListener(new MyButtonClickListener());
    }
    private class MyButtonClickListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (((Button) view).getText() == "下一个") {
                if(imageIDArrayCurrentIndex == imageIDArray.length - 1)
                    imageIDArrayCurrentIndex = 0;
                else {
                    imageIDArrayCurrentIndex++;
                }
            } else {
                if(imageIDArrayCurrentIndex != 0)
                    imageIDArrayCurrentIndex --;
                else{
                    imageIDArrayCurrentIndex = imageIDArray.length - 1;
                }
            }
            imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);
        }
    }
}